<?PHP
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
    $loggedIn = false;
} else{
    $loggedIn = true;
    $userid = $_SESSION['userId'];
}
?>
<header id="header">
    <ul id="menu">
        <li><a href="../pages/index.php"><img id="logo" src="../resources/images/logo.png"></a></li>
        <li class="pc">
            <span>Barer</span>
            <ul>
                <li onclick="location.href='../pages/findBar.php';">Finn bar</li>
                <li onclick="location.href='../pages/registerBar.php';">Registrer bar</li>
            </ul>
        </li>
        <?php
            if($loggedIn){
                echo "<li class='pc'><span>{$_SESSION['firstName']} {$_SESSION['lastName']}</span>
                        <ul>
                            <li onclick='goToProfile();'>Profil</li>
                            <li onclick='logout()'>Logg Ut</li>
                        </ul>
                      </li>";
                echo "<script type='text/javascript'>
                    function goToProfile(){
                        location.href='../pages/userProfile.php?#user= {$_SESSION['userId']}'
                    };
                 </script>";
            } else{
               echo "<li class='pc' onclick='showLogInDialog();'><span>Logg Inn</span></li>";
            }
        ?>
        <li id="menu-btn" class="mobile"><img src="../resources/images/menu.svg"></li>
    </ul>
    
    <table id="mobile-menu">
        <tr>
            <td class="mobile-menu-item">
                Barer
                <table class="mobile-sub-menu">
                    <tr>
                        <td onclick="location.href='../pages/findBar.php';">Finn bar</td>
                    </tr>
                    <tr>
                        <td onclick="location.href='../pages/registerBar.php';">Registrer bar</td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td class="mobile-menu-item">
                Logg inn
                <table class="mobile-sub-menu">
                    <tr>
                        <?php
                            if($loggedIn){
                                echo "<td>
                                         <table class='mobile-sub-menu'>{$_SESSION['firstName']} {$_SESSION['lastName']}
                                            <tr>
                                               <td>Profil</li>
                                            </tr>
                                            <tr>
                                               <td>Logg ut</td>
                                            </tr>
                                         </table>
                                      </td>";
                            } else{
                               echo "<td onclick='showLogInDialog();'>Logg Inn</td>";
                            }
                        ?>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <div id="outOfLogInDialog">
        <div id="logInDialog">
            <div id="logInDialogHeader">Vennligst Logg Inn</div>
            <table>
                <tr>
                    <td><span class="v-align-middle">E-post:</span></td>
                    <td><input type="email" name="email" id="logInEmail"></input></td>
                    <td><img id="email-error" class="hidden v-align-middle" src="../resources/images/error.svg"><img id="email-check" class="hidden v-align-middle" src="../resources/images/check.svg"></td>
                </tr>
                <tr>
                    <td><span class="v-align-middle">Passord:</span></td>
                    <td><input type="password" id="logInPassword"></input></td>
                    <td><img id="pw-error" class="hidden v-align-middle" src="../resources/images/error.svg"><img id="pw-check" class="hidden v-align-middle" src="../resources/images/check.svg"></td>
                </tr>
                <tr>
                    <td><button id="confirmLoginBtn" class="disabled square-btn">Logg inn</button></td>
                    <td><button id="cancelLoginBtn" class="square-btn">Avbryt</button></td>
                </tr>
            </table>
            <table>
                <tr>
                    <td><a id="register-link" onclick="location.href='../pages/signUp.php';">Registrer</a></td>
                    <td style="padding-left: 10px;"><a id="forgotPassword" onclick="showSendNewPassword();">Glemt passord?</a></td>
                </tr>
            </table>
            <table id="sendPasswordTable">
                <tr>
                    <td><input id="sendPasswordInput" placeHolder="Your Email"></input></td>
                    <td><button id="sendPasswordBtn" class="square-btn">Send</button></td>
                </tr>
            </table>
        </div>
    </div>
</header>